package com.xc.hotelmgr.datapusherali.controller;

import com.xc.hotelmgr.datapusherali.pojo.mq.DelGroupRp;
import com.xc.hotelmgr.datapusherali.pojo.mq.DelRpMQ;
import com.xc.hotelmgr.datapusherali.pojo.mq.RpCallBack;
import com.xc.hotelmgr.datapusherali.result.CommResult;
import com.xc.hotelmgr.datapusherali.service.fz.RateplanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/rateplan")
public class FzRaleplanController {

    @Autowired
    private RateplanService rateplanService;

    /**
     * 删除价格政策，前端调用，删除分组下的酒店时，删除分组在店铺上的价格政策。
     * @param delGroupRp
     * @return CommResult
     */
    @RequestMapping(value = "del_group_rp", method = RequestMethod.POST)
    public CommResult delGroupRp(@RequestBody DelGroupRp delGroupRp) {
        Integer groupId = delGroupRp.getGroupId();
        Long hotelId = delGroupRp.getHotelId();
        Integer storeId = delGroupRp.getStoreId();
        boolean result =  rateplanService.delGroupRp(groupId, hotelId, storeId);
        if(result) {
            return new CommResult(0, "succ");
        }else {
            return new CommResult(-1, "fail");
        }
    }

    /**
     * 回调接口推送
     * @param rpCallBack
     * @return
     */
    @RequestMapping(value = "callback_rateplan", method = RequestMethod.POST)
    public String sendUpdateRateplan(@RequestBody RpCallBack rpCallBack) {
        rateplanService.rpCallbackUpdate(rpCallBack);
        return "ok";
    }

    /**
     * 价格政策上下架
     * @param htLogicRoom
     * @return

    @RequestMapping(value = "change_rateplan", method = RequestMethod.POST)
    public String sendRateplan(@RequestBody HtLogicRoom htLogicRoom) {
        String resultPush = pushService.sendRateplan(htLogicRoom);
        System.out.println(resultPush);
        JSONObject jsonObject= new JSONObject();
        jsonObject.put("cancelPolicyType",1);
        System.out.println(jsonObject.toJSONString());
        System.out.println(JSON.toJSONString(htLogicRoom));
        if(resultPush.contains("11")) {
            return "数据推送成功";
        }
        return "ok";
    }*/

    /**
     * 删除价格计划，前端删除自定义价格计划时，同步删除店铺上的自定义价格政策
     * @param delRpMQ
     * @return
     */
    @RequestMapping(value = "delete_rateplan", method = RequestMethod.POST)
    public boolean deleteRateplan(@RequestBody DelRpMQ delRpMQ) {
        Long rpId = delRpMQ.getRpId();
        int opOurRateplanId = delRpMQ.getOpOurRateplanId();
        String appKey = delRpMQ.getAppKey();
        String sessionKey = delRpMQ.getSessionKey();
        String secret = delRpMQ.getSecret();
        return rateplanService.rpDel(rpId, opOurRateplanId, appKey, sessionKey, secret);
    }
}
